<include file="public/layout" />
<body>
<form class="layui-form" action="">
    <input type="hidden" name="id" value="{$info.user_id}" />

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="title" lay-verify="required" value="{$info.title}" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-text-em">最多64个字</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="author" value="{$info.author}" placeholder="请输入文章作者" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-text-em">非必填，最多8个字。</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">摘要</label>
        <div class="layui-input-inline layui-input-wrap">
            <textarea name="digest" placeholder="请输入文章简介" class="layui-textarea">{$info.digest}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="redstar">*</span>封面：</label>
        <!-- <input type="hidden" name="info[pic]" id="pic" lay-verify="required" lay-verType="tips" class="layui-input" value="{$info['pic']}"> -->
        <button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="pic" upload-preview="picPreview" onclick="uploader(this)">上传图片</button>
        <div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
        <div id="picPreview" class="picsList-class-130">
            <div class="layui-imgbox imgbox-required">
                <a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().find('img').attr('src','').hide();getpicsval('pic','picPreview');$(this).hide();" title="删除"><i class="layui-icon layui-icon-close-fill-opaque"></i></a>
                <div class="layui-imgbox-img">
                    <img src="{$info['thumb_url']}"/>
                </div>
                <input autocomplete='off' type="hidden" id="pic" name="thumb_url" lay-verify="required" lay-verType="tips" value="{$info['thumb_url']}" style="cursor:default;">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章内容</label>
        <div class="layui-input-block" style="max-width: 700px;">
            <textarea class="span12 ckeditor" id="content" name="content" title="">{$info.content}</textarea>
        </div>
        <div class="layui-form-mid layui-text-em"></div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="subbtn">确认</button>
        </div>
    </div>
</form>
<load href="__ROOT__/public/plugins/Ueditor/ueditor.config.js"/>
<load href="__ROOT__/public/plugins/Ueditor/ueditor.all.min.js"/>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    var url="{:url('Ueditor/index',array('savePath'=>'weixin_mp_news'))}";
    var ue = UE.getEditor('content',{
        serverUrl :url,
        zIndex: 999,
        initialFrameWidth: "100%", //初化宽度
        initialFrameHeight: 300, //初化高度
        focus: false, //初始化时，是否让编辑器获得焦点true或false
        maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign',//允许的最大字符数 'fullscreen',
        pasteplain:false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
        autoHeightEnabled: true
    });
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });

        // 指定开关事件
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
        // });

        // 提交事件
        form.on('submit(subbtn)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('wechat/handle_news')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            location.href = "{:U('wechat/materials', ['tab' => 'news'])}";
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });
    });

    function img_call_back(fileurl_tmp)
    {
        $("#imagetext").val(fileurl_tmp);
        $("#img_a").attr('href', fileurl_tmp);
        $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
    }
</script>
</body>
</html>